﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AzureGames.Data;
using AzureGames.Domain.Contracts;
using AzureGames.Domain.Models;

namespace AzureGames.Domain.Handlers
{
    public class GetResource
    {
        private readonly IResourceRepository _resourceRepository;

        public GetResource(IResourceRepository resourceRepository)
        {
            _resourceRepository = resourceRepository;
        }

        public virtual GameResource Execute(Guid resourceID)
        {
            try
            {
                var resource = _resourceRepository.GetResource(resourceID);

                return new GameResource(resource);
            }
            catch (InvalidOperationException e)
            {
                throw new BusinessServicesException("Unable to retrieve game resource from database.", e);
            }
        }
    }
}